package com.zqj.project.converter;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zqj.project.dto.ReviewDTO;
import com.zqj.project.entity.ReviewPO;
import com.zqj.project.model.Review;
import com.zqj.project.vo.ReviewVO;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: ReviewConverter
 * @Author: 22001010704 Zhang Qijian
 * @CreateTime: 2024/12/8 20:53
 * @Version: 1.0
 */
public class ReviewConverter {

    private ReviewConverter() {
        throw new IllegalStateException("Utility Class");
    }

    public static ReviewVO toReviewVo(Review orderDetail) {
        return BeanUtil.toBean(orderDetail, ReviewVO.class);
    }

    public static Review toReviewModel(ReviewDTO orderDetailDto) {
        return BeanUtil.toBean(orderDetailDto, Review.class);
    }

    public static Review toReviewModel(ReviewPO orderDetailPo) {
        return BeanUtil.toBean(orderDetailPo, Review.class);
    }

    public static ReviewPO toReviewPo(Review orderDetail) {
        return BeanUtil.toBean(orderDetail, ReviewPO.class);
    }

    public static List<ReviewVO> toReviewVoList(List<Review> orderDetailModelList) {
        if (CollUtil.isEmpty(orderDetailModelList)) {
            return Collections.emptyList();
        }
        return orderDetailModelList.stream().map(e -> BeanUtil.toBean(e, ReviewVO.class)).toList();
    }

    public static List<Review> toReviewModelList(List<ReviewPO> orderDetailPoList) {
        if (CollUtil.isEmpty(orderDetailPoList)) {
            return Collections.emptyList();
        }
        return orderDetailPoList.stream().map(e -> BeanUtil.toBean(e, Review.class)).toList();
    }

    public static IPage<ReviewVO> toReviewVoPage(IPage<Review> orderDetailModelPage) {
        IPage<ReviewVO> orderDetailVoPage = new Page<>(orderDetailModelPage.getCurrent(), orderDetailModelPage.getSize());
        List<ReviewVO> orderDetailVoList = new ArrayList<>();
        if (CollUtil.isNotEmpty(orderDetailModelPage.getRecords())) {
            orderDetailModelPage.getRecords().forEach(entity -> orderDetailVoList.add(BeanUtil.toBean(entity, ReviewVO.class)));
            orderDetailVoPage.setRecords(orderDetailVoList);
            orderDetailVoPage.setTotal(orderDetailModelPage.getTotal());
        }
        return orderDetailVoPage;
    }

}